import request from "@/utils/request.js";

/**
 * 获取题目列表
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProblemListService = () => {
    return request.get('/problems');
}

/**
 * 新增题目
 * @param {Object} data - 题目数据
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const addProblemService = (data) => {
    return request.post('/problems', data);
}

/**
 * 更新题目
 * @param {Object} data - 题目数据
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateProblemService = (data) => {
    return request.put(`/problems/${data.id}`, data);
}

/**
 * 删除题目
 * @param {number} id - 题目ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteProblemService = (id) => {
    return request.delete(`/problems/${id}`);
}

/**
 * 获取题解
 * @param {number} id - 题目ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProblemSolutionService = (id) => {
    return request.get(`/problems/${id}/solution`);
}

/**
 * 获取题解统计数据
 * @param {number} days - 天数(7/15/30)
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSolutionStatisticsService = (days) => {
    return request.get(`/solutions/statistics?days=${days}`);
}

/**
 * 获取题解难度分布数据
 * @param {number} days - 天数(7/15/30)
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSolutionDifficultyStatsService = (days) => {
    return request.get(`/solutions/difficulty-stats?days=${days}`);
}

/**
 * 获取题解列表
 * @param {number} problemId - 题目ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSolutionListService = (problemId) => {
    return request.get(`/problems/${problemId}/solutions`);
}

/**
 * 新增题解
 * @param {Object} data - 题解数据
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const addSolutionService = (data) => {
    return request.post(`/problems/${data.problemId}/solutions`, data);
}

/**
 * 更新题解
 * @param {Object} data - 题解数据
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateSolutionService = (data) => {
    return request.put(`/problems/${data.problemId}/solutions/${data.id}`, data);
}

/**
 * 删除题解
 * @param {number} problemId - 题目ID
 * @param {number} solutionId - 题解ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteSolutionService = (problemId, solutionId) => {
    return request.delete(`/problems/${problemId}/solutions/${solutionId}`);
}